package aom.example.security.service.impl;

import aom.example.security.domain.SysRoleEntity;
import aom.example.security.mapper.SysRoleMapper;
import aom.example.security.service.SysRoleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/11 14:49
 * @since JDK 1.8
 */
@Service("sysRoleService")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity> implements SysRoleService {

    @Override
    public SysRoleEntity getSysRoleEntityByUserName(String userName) {
        LambdaQueryWrapper<SysRoleEntity> sysRoleEntityLambdaQueryWrapper=new LambdaQueryWrapper<>();
        sysRoleEntityLambdaQueryWrapper.eq(SysRoleEntity::getRoleName,userName);
        return super.baseMapper.selectOne(sysRoleEntityLambdaQueryWrapper);
    }

    /**
     * 通过uid查询用户当前具有的角色
     * @param userid
     * @return
     */
    @Override
    public List<Map<String, Object>> selectRoleUserByUserId(String userid) {
        List<Map<String, Object>> mapList=this.baseMapper.selectRoleUserByUserId(userid);
        return mapList;
    }

    @Override
    public boolean insertSysUserRole(String userid, String roleid) {
        return this.baseMapper.insertSysUserRole(userid,roleid);
    }

    @Override
    public List<Map<String, Object>> selectUserNotRole(String uid) {
        return this.baseMapper.selectUserNotRole(uid);
    }

    @Override
    public boolean deleteSysUserRoleById(String id) {
        return this.baseMapper.deleteSysUserRoleById(id);
    }


}
